package com.ssm.hyl.dao;

import java.sql.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.mysql.cj.jdbc.Driver;

/**
 * UserDaoImpl
 *
 * @author hyl
 * @date 2024-12-13
 */
public class UserDaoImpl implements UserDao{
    @Override
    public List findAll() throws SQLException {
        //1加载驱动
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        //2.获取链接
        Connection connection = DriverManager.getConnection("","","");
        //3.编写sql
        String sql = "select * from user";
        //4.创建执行对象
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        //5.执行
        ResultSet resultSet = preparedStatement.executeQuery();
        //6.处理结果
        List list = new ArrayList();
        while (resultSet.next()){
            Object user = new Object();
            list.add(user);
        }
        //7.释放资源
        resultSet.close();
        preparedStatement.close();
        connection.close();
        return list;
    }

    @Override
    public Object findById(int id) throws SQLException {
        //1加载驱动
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        //2.获取链接
        Connection connection = DriverManager.getConnection("","","");
        //3.编写sql
        String sql = "select * from user";
        //4.创建执行对象
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        //5.执行
        ResultSet resultSet = preparedStatement.executeQuery();
        //6.处理结果
        Object user = new Object();
        while (resultSet.next()){

        }
        //7.释放资源
        resultSet.close();
        preparedStatement.close();
        connection.close();
        return user;
    }

    @Override
    public int add(Object user) {
        return 0;
    }

    @Override
    public int delete(int id) {
        return 0;
    }

    @Override
    public int update(Object user) {
        return 0;
    }
}
